
package org.argetr.resim.proc.math;

import java.awt.image.renderable.ParameterBlock;

import javax.media.jai.JAI;
import javax.media.jai.PlanarImage;

import org.argetr.resim.proc.ConnectionRule;
import org.argetr.resim.proc.data.ConstDA;
import org.argetr.resim.proc.data.ConverterUT;
import org.argetr.resim.proc.data.Data;
import org.argetr.resim.proc.data.ImageDA;



public class ConstLogicalPR extends LogicalPR {
	int[] _consts;
	protected void setConnectionRules(ConnectionRule connRule){
		connRule.addInType(ImageDA.class, 0);
		connRule.addInType(ConstDA.class, 1);
		connRule.addOutType(ImageDA.class);
	}
	public void setConsts(int[] consts) {
		_consts = consts;
		
	}
    public int[] getConsts(){
    	return _consts;
    }
    
	public Data process() {
		PlanarImage im = getInputAsPlanarImage();
		ParameterBlock pb = new ParameterBlock();
		pb.addSource(im);
		ConstDA constDA = getInputAsConstDA(1);
		int constVal = (int)constDA.getValue();
		int nBand = getInputAsImageDA().getNBands();
		int[] consts = ConverterUT.get1DIntArray(constVal, nBand);
		setConsts(consts);
		pb.add(getConsts());
		PlanarImage imout = null;
		switch (getParamOpType()) {
		case MathPR.AND:
			imout = JAI.create("andconst", pb, null);
			break;
		case MathPR.OR:
			imout = JAI.create("orconst", pb, null);
			break;
		case MathPR.XOR:
			imout = JAI.create("xorconst", pb, null);
			break;
		default:
			break;
		}
		ImageDA out = new ImageDA(imout);
		setOutput(out);
		return getOutput();
	}
}
